package test.test;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.mm_testApplication;
import com.itheima.test.entity.User;
import com.itheima.test.mapper.UserClassMapper;
import com.itheima.test.mapper.UserDepartMapper;
import com.itheima.test.mapper.UserMapper;
import com.itheima.test.service.UserService;
import com.itheima.test.vo.UserClass;
import com.itheima.test.vo.UserDepart;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;


/**
 * @description:7
 * @author: Java
 * @date: 2021/3/24 21:56
 */
@SpringBootTest(classes = mm_testApplication.class)
@RunWith(SpringRunner.class)
public class testMapper {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private UserClassMapper userClassMapper;
    @Autowired
    private UserDepartMapper userDepartMapper;
    @Autowired
    private UserService userService;

    /*@Test
    public void testSelectById() {
        //1. 构建分页对象
        Page<User> page = new Page<>(1, 2);
        //2.创建查询条件构建器
        LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
        //3.设置条件
        wrapper.eq(User::getRoleId, 0);
        //4.调用业务查询
//        IPage<User> pageResult = userMapper.selectPage(page, wrapper);
        List<User> test = userMapper.findbyPage();
        test.forEach(System.out::println);
    }
    @Test
    public void testSelectById2() {
        //1. 构建分页对象
        Page<User> page = new Page<>(1, 2);
        //4.调用业务查询
        IPage<User> stringIPage = userMapper.selectByPageStu(page);
        List<User> records = stringIPage.getRecords();
        records.forEach(System.out::println);
    }
    @Test
    public void testSelectById3() {
        //1. 构建分页对象
        Page<User> page = new Page<>(1, 2);
        //2.创建查询条件构建器
        QueryWrapper<User> wrapper = new QueryWrapper<User>();
        //3.设置条件
        wrapper.eq("role_id", 0)

        ;
        //4.调用业务查询

        IPage<User> userIPage = userMapper.selectMyPage(page, wrapper);
        List<User> records = userIPage.getRecords();
        records.forEach(System.out::println);
    }*/
    @Test
    public void testadd1() {
        User user = new User();
        user.setUsername("test");
        //      插入班级
        UserClass uc = new UserClass();
        uc.setUsername(user.getUsername());
        uc.setCid(1);
        userClassMapper.insert(uc);
//      插入院系
        UserDepart ud = new UserDepart();
        ud.setUsername(user.getUsername());
        ud.setDid(1);
        userDepartMapper.insert(ud);
    }
    @Test
    public void testServiceadd() {
        User user = new User();
        user.setUsername("test123");
        userService.addUser(user);
    }
    @Test
    public void testselect() {
        //看看between的语法
        //1.创建查询条件构建器
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        //2.设置条件
        wrapper.between("role_id", 1, 2);
        userMapper.selectList(wrapper);
    }
    @Test
    public void testupdate() {
        User user = new User();
        user.setId(9);
        user.setStatus(1);
        //看看update的语法
        userMapper.updateById(user);
    }

}
